package com.jyh.homework.homework3;

/**
 * @Author JYH
 * @Date 2024/8/7 16:57
 * @Description
 */
public class HomeWork3 {
    public static void main(String[] args) {
        //Lambda表达式   匿名内部类为:Thread t1=new Thread(new Runnable{});
        Thread t1 = new Thread(()->{

                for (int i = 1; i <= 5; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"第"+i+"次执行");
                }
            }
       ,"子线程");
        t1.start();

        for (int i = 1; i <= 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"第"+i+"次执行");
        }
    }
}
